import {ref, computed} from 'vue'
import {defineStore} from 'pinia'
import {getCountMsgByFlk} from '@/api/api'
import {useBaseParamStore} from './baseParams'

// 种群信息
export const useFlockInfoStore = defineStore('flockInfo', () => {
    const flockInfo = ref({})
    // 获取响应式对象
    const isEmpty = computed(() => (flockInfo.value.fid ? false : true))
    const getFlockInfo = computed(() => flockInfo)

    // 更新方法
    async function getLatestFlockInfo() {
        const baseParam = useBaseParamStore()
        try {
            let res = await getCountMsgByFlk(baseParam.baseParam.flockId)
            flockInfo.value = res.data
            return flockInfo
        } catch (error) {
            return null;
        }
    }

    return {flockInfo, isEmpty, getFlockInfo, getLatestFlockInfo}
})
